﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Net;

using EHTWebsite.Code;
using EHTWebsiteProject.Code.BLL;
using System.Resources;
using System.Threading;
using System.Globalization;
using System.Text;

namespace EHTWebsiteProject.Administrator
{
    public partial class EHTImageCompany : System.Web.UI.Page
    {
        public Boolean IsVN = true;
        private String languageCode = "vi-VN";
        private String message = "";

        private Int32 pageIndex = 1;
        private Int32 pageSize = 30;
        private Int32 totalRecord;

        private ResourceManager rm = new ResourceManager("Resources.SiteMap", System.Reflection.Assembly.Load("App_GlobalResources"));

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

                try
                {
                    languageCode = Session[HangSo.LANGUAGE_CODE].ToString();
                    Session["NgonNgu"] = languageCode;
                    if (languageCode == "en-us")
                    {
                        IsVN = false;
                    }

                }
                catch (Exception ex)
                {
                }
                try
                {
                    message = Request.QueryString["Message"].ToString();
                    if (message != "")
                        ltrErorr.Text = HelpMethod.ApplySuccess(message);
                }
                catch
                {

                }
                Thread.CurrentThread.CurrentCulture = new CultureInfo(languageCode);
                LoadLanguage(Thread.CurrentThread.CurrentCulture);
                LoadHinhAnhCongty();
            }
        }
        /// <summary>
        /// Ham load ngon ngu
        /// </summary>
        /// <param name="ci"></param>
        public void LoadLanguage(CultureInfo ci)
        {
            lbDichVu.Text = rm.GetString("lbDichVu", ci);           
            lbHelp.Text = rm.GetString("lbHelp", ci);           
            lbThongTinCongTy.Text = rm.GetString("lbThongTinCongTy", ci);
            lbHoTro.Text = rm.GetString("lbHoTro", ci);            
            lbHinhANhCongTy.Text = rm.GetString("lbHinhANhCongTy", ci);
            lbImageManager.Text = rm.GetString("lbImageManager",ci);
            lbAddNew.Text = rm.GetString("lbAddNew", ci);
            lbBat.Text = rm.GetString("lbBat", ci);
            lbDel.Text = rm.GetString("lbDel", ci);
            lbEdit.Text = rm.GetString("lbEdit", ci);
            lbHelp.Text = rm.GetString("lbHelp", ci);

        }

        protected void ImgDel_Click(object sender, ImageClickEventArgs e)
        {
            ArrayList arr = new ArrayList();
            if (Session[HangSo.LANGUAGE_CODE].ToString() == "vi-VN")
            {
                foreach (RepeaterItem rp in rpImageCompany.Items)
                {
                    CheckBox ckMenu = (CheckBox)rp.FindControl("ckMenu");
                    Label lbDelID = (Label)rp.FindControl("lbDelID");
                    if (ckMenu.Checked == true)
                    {
                        arr.Add(lbDelID.Text);
                    }
                }
            }
            else
            {
                foreach (RepeaterItem rp in rpImageCompanyOther.Items)
                {
                    CheckBox ckMenu = (CheckBox)rp.FindControl("ckMenu");
                    Label lbDelID = (Label)rp.FindControl("lbDelID");
                    if (ckMenu.Checked == true)
                    {
                        arr.Add(lbDelID.Text);
                    }
                }
            }


            for (int i = 0; i < arr.Count; i++)
                HinhAnhCongTyProvider.DeleteHinhAnhCongTyByHinhAnhID(Int32.Parse(arr[i].ToString()));
            LoadHinhAnhCongty();
        }

        protected void ImgEdit_Click(object sender, ImageClickEventArgs e)
        {
            Int32 ID = 0;
            Int32 Count = 0;
            if (Session[HangSo.LANGUAGE_CODE].ToString() == "vi-VN")
            {
                foreach (RepeaterItem rp in rpImageCompany.Items)
                {
                    CheckBox ckMenu = (CheckBox)rp.FindControl("ckMenu");
                    Label lbDelID = (Label)rp.FindControl("lbDelID");
                    if (ckMenu.Checked == true)
                    {
                        ID = Int32.Parse(lbDelID.Text);
                        Count++;
                    }
                }
            }
            else
            {
                foreach (RepeaterItem rp in rpImageCompanyOther.Items)
                {
                    CheckBox ckMenu = (CheckBox)rp.FindControl("ckMenu");
                    Label lbDelID = (Label)rp.FindControl("lbDelID");
                    if (ckMenu.Checked == true)
                    {
                        ID = Int32.Parse(lbDelID.Text);
                        Count++;
                    }
                }
            }


            if (Count > 1 || Count == 0)
            {
                String messa = "";
                if (IsVN == true)
                    messa = HangSo.Eorr_Edit;
                else
                    messa = HangSo.Eorr_EditOther;
                ltrErorr.Text = HelpMethod.ErorrLogin(messa);
            }
            else
            {
                Response.Redirect("EHTImageCompanyUI.aspx?HinhAnhID=" + ID.ToString());
            }
        }



        protected void ImaTat_Click(object sender, ImageClickEventArgs e)
        {
            ArrayList arr = new ArrayList();
            if (Session[HangSo.LANGUAGE_CODE].ToString() == "vi-VN")
            {
                foreach (RepeaterItem rp in rpImageCompany.Items)
                {
                    CheckBox ckMenu = (CheckBox)rp.FindControl("ckMenu");
                    Label lbDelID = (Label)rp.FindControl("lbDelID");
                    if (ckMenu.Checked == true)
                    {
                        arr.Add(lbDelID.Text);
                    }
                }
            }
            else
            {
                foreach (RepeaterItem rp in rpImageCompanyOther.Items)
                {
                    CheckBox ckMenu = (CheckBox)rp.FindControl("ckMenu");
                    Label lbDelID = (Label)rp.FindControl("lbDelID");
                    if (ckMenu.Checked == true)
                    {
                        arr.Add(lbDelID.Text);
                    }
                }
            }


            for (int i = 0; i < arr.Count; i++)
                HinhAnhCongTyProvider.ChangePublish(Int32.Parse(arr[i].ToString()), false);
            LoadHinhAnhCongty();
        }

        protected void ImgBat_Click(object sender, ImageClickEventArgs e)
        {
            ArrayList arr = new ArrayList();
            if (Session[HangSo.LANGUAGE_CODE].ToString() == "vi-VN")
            {
                foreach (RepeaterItem rp in rpImageCompany.Items)
                {
                    CheckBox ckMenu = (CheckBox)rp.FindControl("ckMenu");
                    Label lbDelID = (Label)rp.FindControl("lbDelID");
                    if (ckMenu.Checked == true)
                    {
                        arr.Add(lbDelID.Text);
                    }
                }
            }
            else
            {
                foreach (RepeaterItem rp in rpImageCompanyOther.Items)
                {
                    CheckBox ckMenu = (CheckBox)rp.FindControl("ckMenu");
                    Label lbDelID = (Label)rp.FindControl("lbDelID");
                    if (ckMenu.Checked == true)
                    {
                        arr.Add(lbDelID.Text);
                    }
                }
            }


            for (int i = 0; i < arr.Count; i++)
                HinhAnhCongTyProvider.ChangePublish(Int32.Parse(arr[i].ToString()), true);
            LoadHinhAnhCongty();

        }


        public void LoadHinhAnhCongty()
        {
            if (Session[HangSo.LANGUAGE_CODE].ToString() == "vi-VN")
            {
                rpImageCompany.DataSource = HinhAnhCongTyProvider.GetHinhAnhCongTys(false, pageIndex, pageSize, out totalRecord);
                rpImageCompany.DataBind();
                pnImageCompanyOther.Visible = false;
            }
            else
            {
                rpImageCompanyOther.DataSource = HinhAnhCongTyProvider.GetHinhAnhCongTys(false, pageIndex, pageSize, out totalRecord);
                rpImageCompanyOther.DataBind();
                pnImageCompany.Visible = false;
            }


            this.PaggingControl1.PageIndex = pageIndex;
            this.PaggingControl1.TotalRecord = totalRecord;
            this.PaggingControl1.PageURL = "EHTImageCompany.aspx";
        }

        public void CheckAll(object sender, System.EventArgs e)
        {
            CheckBox ckAll = (CheckBox)sender;
            if (Session[HangSo.LANGUAGE_CODE].ToString() == "vi-VN")
            {
                if (ckAll.Checked)
                {
                    foreach (RepeaterItem rp in rpImageCompany.Items)
                    {
                        CheckBox ckMenu = (CheckBox)rp.FindControl("ckMenu");
                        ckMenu.Checked = true;
                    }
                }
                else
                {
                    foreach (RepeaterItem rp in rpImageCompany.Items)
                    {
                        CheckBox ckMenu = (CheckBox)rp.FindControl("ckMenu");
                        ckMenu.Checked = false;
                    }
                }
            }
            else
            {
                if (ckAll.Checked)
                {
                    foreach (RepeaterItem rp in rpImageCompanyOther.Items)
                    {
                        CheckBox ckMenu = (CheckBox)rp.FindControl("ckMenu");
                        ckMenu.Checked = true;
                    }
                }
                else
                {
                    foreach (RepeaterItem rp in rpImageCompanyOther.Items)
                    {
                        CheckBox ckMenu = (CheckBox)rp.FindControl("ckMenu");
                        ckMenu.Checked = false;
                    }
                }
            }
        }

        protected void rpImageCompany_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Label lbStatus = (Label)e.Item.FindControl("lbStatus");
            Image ImagStatus = (Image)e.Item.FindControl("ImagStatus");
            try
            {
                if (lbStatus.Text == "True")
                    ImagStatus.ImageUrl = "~/images/tick.png";
                else
                    ImagStatus.ImageUrl = "~/images/Close.png";
            }
            catch
            {

            }
        }

        protected void rpImageCompanyOther_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            Label lbStatus = (Label)e.Item.FindControl("lbStatus");
            Image ImagStatus = (Image)e.Item.FindControl("ImagStatus");
            try
            {
                if (lbStatus.Text == "True")
                    ImagStatus.ImageUrl = "~/images/tick.png";
                else
                    ImagStatus.ImageUrl = "~/images/Close.png";
            }
            catch
            {

            }
        }
    }
}